import cache from '@/config/cache.js'
import settings from '@/common/settings/index.js'
import utils from '@/config/utils'
/**
 * 判断登录用户权限
 * @param {*} value
 * @returns {string}
 */
function checkRank(apiUrl) {
	let userAccess = cache.get('userAccess');
	if(!userAccess){
		return false;
	}
	
	if(userAccess.indexOf(apiUrl+',') >=0){
		return true;
	}
	return false;
}


//获取小程序底部导航
function getBottomBar() {
	var token = cache.get("token");
	var user = cache.get("userinfo");
	let isLogin = !utils.isEmpty(token) && user

	let textList =[];
	if(isLogin){
		let userInfo = cache.get('userinfo');
		if(userInfo && userInfo.user_type){
			switch(userInfo.user_type){
				case 'visit'://游客
					//textList = settings.tabBarList
					 textList = settings.visitTabBar
					break;
				case 'company'://公司
					textList = settings.companyTabBar
					break;
				case 'park'://园区管理员
					textList = settings.parkTabBar
					break;
				case 'pmc'://物业
					textList = settings.pmcTabBar
					break;
				case 'channel'://渠道
					textList = settings.channelTabBar
					break;
				default:
					textList = settings.visitTabBar
			}
		}
		
	}else{
		textList = settings.visitTabBar
	}
	return textList;
}

//获取小程序底部导航
function getBottomBarByTpye(value) {

	let textList =[];

	switch(value){
		case 'visit'://游客
			 textList = settings.visitTabBar
			break;
		case 'company'://公司
			textList = settings.companyTabBar
			break;
		case 'park'://园区管理员
			textList = settings.parkTabBar
			break;
		case 'pmc'://物业
			textList = settings.pmcTabBar
			break;
		case 'channel'://渠道
			textList = settings.channelTabBar
			break;
		case 'unlogin'://未登录
			textList = settings.unloginTabBar
			break;
		default: //未登录的时候不知道为什么传入的是null
			textList = settings.unloginTabBar
	}
	return textList;
}


module.exports = {
    checkRank: checkRank,
	getBottomBar:getBottomBar,
	getBottomBarByTpye:getBottomBarByTpye,
}